 
 package org.jetnuke.modules.blog.utils;

import net.jforum.dao.UserDAO;
import net.jforum.entities.User;

import org.apache.xmlrpc.XmlRpcException;

public class BaseAPIHandler {
	
    public static final int AUTHORIZATION_EXCEPTION = 0001;
    public static final String AUTHORIZATION_EXCEPTION_MSG = 
            "Invalid Username and/or Password";
            
    public static final int UNKNOWN_EXCEPTION = 1000;
    public static final String UNKNOWN_EXCEPTION_MSG = 
            "An error occured processing your request";
    
    public static final int BLOGGERAPI_DISABLED = 1000;
    public static final String BLOGGERAPI_DISABLED_MSG = 
            "You have not enabled Blogger API support for your weblog";
    
    public static final int UNSUPPORTED_EXCEPTION = 1001;
    public static final String UNSUPPORTED_EXCEPTION_MSG = 
            "Unsupported method - Roller does not support this method";
            
    public static final int INVALID_POSTID = 2000;
    public static final String INVALID_POSTID_MSG = 
            "The entry postid you submitted is invalid";
            
    public static final int NOBLOGS_EXCEPTION = 3000;
    public static final String NOBLOGS_EXCEPTION_MSG = 
            "There are no categories defined for your user";

    public static final int UPLOAD_DENIED_EXCEPTION = 4000;
    public static final String UPLOAD_DENIED_EXCEPTION_MSG = 
            "Upload denied";
    
    
         
    protected User validate(String username, String password) throws Exception{
    	UserDAO um = net.jforum.dao.DataAccessDriver.getInstance().newUserDAO();
		User user = null;
		if(username.length()>0 && password.length()>0)
			user=um.validateLogin(username, password);
		if(user==null)
			throw new XmlRpcException(AUTHORIZATION_EXCEPTION,AUTHORIZATION_EXCEPTION_MSG);
		return user;
    }

}
